package ljl.alg.jianzhioffer.round2;

import commons.ListNode;

public class _25_merge_sorted_linklist {
    
    /**
     * 也是很熟练的背出来了
     * */
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode head = new ListNode();
        ListNode p = head;
        while (l1 != null && l2 != null) {
            int v1 = l1.val, v2 = l2.val;
            // 这一开始写成 > 了，我透？
            if (v1 < v2) {
                p.next = l1;
                l1 = l1.next;
            } else {
                p.next = l2;
                l2 = l2.next;
            }
            p = p.next;
        }
        p.next = l1 == null ? l2 : l1;
        return head.next;
    }
}
